package dtrs;

import helpers.d;
import soenudp.Command;
import soenudp.UDPException;
import soenudp.UDPHelper;
import soenudp.UDPMessage;

public class FakeFE {

    static int    LeaderPortMTL  = 20020;
    int    LeaderPortTOR  = 20060;
    

    static String IP_OF_MTL_LEAD = "127.0.0.1"; // Leader will have to PING the FE 1st (the same a registering)
                                         // This can changes when the replica becomes a leader... 
                                         // Or by the election alogoritm.
    
    static String IP_OF_TOR_LEAD = "127.0.0.1";
    
    /**
     * This is basically a dumm FronEnd with no CORBA
     */
    public static void main(String[] args)
    {
        try
        {
            UDPHelper udpClient = new UDPHelper();
            udpClient.startUnicastClient("FRONTEND");
            d.sleep(1*1000); // 1 Second delay
            
            /* ShowID, CustomerID, Tickets Amount, TransacID(optional for now), Optional Text */
            UDPMessage aCheck  = new UDPMessage("MTL222", "123456", Command.CHECK,   0,  0, null); 
            UDPMessage aResrv  = new UDPMessage("MTL222", "123456", Command.RESERVE, 15, 0, null);
            UDPMessage aCancel = new UDPMessage("MTL222", "123456", Command.CANCEL,  10, 0, null);
            UDPMessage aExchag = new UDPMessage("MTL222", "123456", Command.EXCHANGE,  1, 0, null, "TOR444", 3);
            // comment this loop if you just want a single request
            while (true) // Maybe it will bother you all-ways receiving request
            {
                udpClient.sendToNode(IP_OF_MTL_LEAD, LeaderPortMTL, aCheck);
                d.sleep(10*1000); // 10 Seconds delay
                udpClient.sendToNode(IP_OF_MTL_LEAD, LeaderPortMTL, aResrv);
                d.sleep(10*1000);
                udpClient.sendToNode(IP_OF_MTL_LEAD, LeaderPortMTL, aCancel);
                d.sleep(10*1000);
                udpClient.sendToNode(IP_OF_MTL_LEAD, LeaderPortMTL, aExchag);
                d.sleep(10*1000);
            }
            
        } catch (UDPException e)
        {
            e.printStackTrace();
        }
    }

}
